package com.cathyjava.easyflows.workflow.parallel;

import com.cathyjava.easyflows.work.Work;
import com.cathyjava.easyflows.work.WorkContext;
import com.cathyjava.easyflows.work.WorkReport;
import com.cathyjava.easyflows.workflow.AbstractWorkFlow;

import java.util.List;

/**
 * @author chenjing
 * @date 2021/5/12
 */
public class ParallelWorkFlow extends AbstractWorkFlow {
    private String name;
    private ParallelFlowExecutor parallelExecutor;
    private List<Work> workUnits;

    public ParallelWorkFlow(String name, List<Work> works, ParallelFlowExecutor executor) {
        super(name);
        this.workUnits = works;
        this.parallelExecutor = executor;
    }

    @Override
    public ParallelFlowReport execute(WorkContext workContext) {
        ParallelFlowReport parallelReports = new ParallelFlowReport();
        List<WorkReport> workReports = this.parallelExecutor.executeInParallel(this.workUnits, workContext);
        parallelReports.addAll(workReports);
        return parallelReports;
    }
}
